<template>
	<view class="container">
		<view class="header">
			<u-search :showAction="showAction" placeholder="请输入BOM单号" v-model="queryParams.bomId" @search="handleSearch"></u-search>
		</view>
		<view class="content">
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" 
				@scrolltolower="lower" @refresherrefresh="onRefresh" refresher-enabled="true" :refresher-triggered="triggered">
				<view v-if="list.length>0"  class="scroll-view-item" v-for="(item,index) in list" :key="index">
					<view class="items">
						<view class="itemsBlock">
							{{item.productName||''}}（{{item.no}}）
						</view>
						
						<view class="buts" @click="handleSubmit(item,index)">确定</view>
					</view>
				</view>
				<view v-if="list.length==0" class="None">
					暂无信息
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getProductionOrder
	} from '@/api/store.js'
	export default {
		data() {
			return {
				triggered:false,
				showAction:false,
				keyword:'',
				scrollTop:0,
				queryParams: {
					pageNo: 1, //页码
					pageSize: 20, //条数
					bomId:''
				},
				list: [], //列表数据
				total: 0, //总条数
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			// 获取BOM单列表
			async getList() {
				let res = await getProductionOrder(this.queryParams)
				this.list = [...this.list,...res.data.list]
				this.total = res.data.total
				setTimeout(()=>{
					this.triggered = false
				},500)
			},
			// 搜索
			handleSearch(){
				this.queryParams.pageNo=1
				this.list=[]
				this.getList()
			},
			// 确定
			handleSubmit(item,index){
				console.log('item:',item);
				
				uni.$emit('materials', { data:item});
				uni.$emit('finishedProduct', { data:item});
				
				uni.navigateBack()
			},
			// 上拉加载
			lower(){
				if(this.list.length < this.total){
					this.queryParams.pageNo++
					this.getList()
				}
			},
			// 下拉刷新
			onRefresh(){
			this.triggered = true
				this.queryParams.pageNo=1
				this.list = []
				this.getList()
			}
		}
	}
</script>

<style scoped>
	.buts{
		width: 90rpx;
		height: 50rpx;
		line-height: 50rpx;
		text-align: center;
		font-size: 22rpx;
		background-color: #007DFE;
		color: #FFFFFF;
		border-radius: 10rpx;
	}
	.itemsBlock{
		height: 99rpx;
		line-height: 99rpx;
		width: 550rpx;
		 text-overflow: ellipsis;
		    overflow: hidden;
		    word-break: break-all;
		    white-space: nowrap;
	}
	.None{
		width: 100%;
		height: 150rpx;
		font-size: 26rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #999;
	}
	.items{
		width: 100%;
		height: 100rpx;
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #EBEBEB;
		font-size: 26rpx;
		justify-content: space-between;
	}
	.header{
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #FFFFFF;
		margin-bottom: 15rpx;
		margin-top: 15rpx;
	}
	.content{
		width: 720rpx;
		height: 100vh;
		background-color: #FFFFFF;
		border-radius: 5rpx;
		padding: 10rpx;
		box-sizing: border-box;
	}
	.scroll-Y{
		/* background-color: #007DFE; */
		width: 690rpx;
		height: calc(100vh - 150rpx);
	}
	.container{
		width: 750rpx;
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: #F8F8F8;
	}
</style>